/**
 * @file convert.cpp
 * @author  ()
 * @brief 转换图像文件格式
 * @version 0.1
 * @date 2024-09-21
 *
 * @copyright Copyright (c) 2024
 *
 */
#include <iostream>
#include <opencv2/core/utility.hpp>
#include <opencv2/opencv.hpp>
#include <string>
// #include "cmdline/cmdline.h"
#include "env.h"

int main(int argc, char **argv) {
#if 0
    cmdline::parser parser;

    parser.add<std::string>("input", 'i', "input file", true);
    parser.add<std::string>("output", 'o', "output file", true);

    parser.parse_check(argc, argv);

#endif
    cv::CommandLineParser parser(argc, argv,
                                 "{help h usage? || Print help info}"
                                 "{@input || input file}"
                                 "{@output || output image}");

    // ./opencv_convert --help(-h) 输出帮助信息
    // ./opencv_convert input.jpg output.png  运行程序正常功能

    if (parser.has("help")) {
        parser.printMessage();
        return 0;
    }

    auto input  = kResourcesDir + parser.get<std::string>("@input");
    auto output = kResourcesDir + parser.get<std::string>("@output");

    cv::Mat img = cv::imread(input);
    if (img.empty()) {
        std::cerr << "Could not open or find the image" << '\n';
        return -1;
    }

    cv::imwrite(output, img);
    return 0;
}
